package sunwin.yoms.service.person;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sunwin.yoms.comm.YomsException;
import sunwin.yoms.dao.UserLevelDao;
import sunwin.yoms.domain.person.UserLevelDomain;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by watson on 2015/7/30.
 */
@Service
public class UserLeveService {
    @Autowired
    private UserLevelDao userLevelDao;

    //查询
    public List<UserLevelDomain> getUserLeve(UserLevelDomain userLevelDomain) {
        List<UserLevelDomain> userLevelDomains = userLevelDao.getDomainCollection(userLevelDomain);
        return userLevelDomains;
    }

    //id查询
    public UserLevelDomain getUserLeveById(int userLevelId) {
        return userLevelDao.getDomainById(userLevelId);
    }

    //总数
    public int getUerLeveCount() {
        return userLevelDao.getDomainCount();
    }

    //增加
    public void addUserLeve(UserLevelDomain userLevelDomain) throws YomsException {
        if (userLevelDao.addDomain(userLevelDomain) != 1) {
            throw new YomsException("增加用户等级失败");
        }
    }

    //删除
    public void deleteUserLeve(UserLevelDomain userLevelDomain) throws YomsException {
        if (userLevelDao.deleteDomain(userLevelDomain) != 1) {
            throw new YomsException("删除用户等级失败");
        }
    }

    //更新
    public void upUserLeve(UserLevelDomain userLevelDomain) throws YomsException {
        if (userLevelDao.updateDomain(userLevelDomain) != 1) {
            throw new YomsException("更新用户等级失败");
        }
    }
}
